// components/landscape.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */

  properties: {
  },

  /**
   * 组件的初始数据
   */
  data: {
     dataList:[],
     activeId:{},
     shopData:[],
     shopInfo:{
      categoryFirst:"",
      categorySecond:""
     },
     show:false,
     phone:""
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleChildData(e) {
      // console.log(e)
      if(e.detail==null){
        this.setData({
          activeId:{}
        })
      }else{
        this.setData({
          activeId:this.data.dataList[e.detail]
        })
      }
      
    },
    //获取二级分类和商品
    async getover(e){
      this.setData({
        ['shopInfo.categoryFirst']:e
      })
      let res = await app.api.findCategory({categoryFirst:e})
      // console.log(res.data)
      if(res.code!=200)return
        this.setData({
         dataList:res.data
       })
       this.getShops()
    },
    //获取所有商品
   async getShops(){
    let res = await app.api.getShoplist(this.data.shopInfo)
    // console.log('善地商品:',res)
     if(res.code!=200)return
     res.data.data.forEach(element => {
      element.picUrls= JSON.parse(element.picUrls.replace(/\'/g,"\""))[0]
      element.yyTimes= JSON.parse(element.yyTimes)
     })
     this.setData({
      shopData:res.data.data
    })
    },
    //咨询
    getPhone(e){
        // console.log(e.currentTarget.dataset.phone)
        this.setData({
          phone:e.currentTarget.dataset.phone,
          show:true
        })
    },
    //关闭咨询
    clearAction(){
        this.setData({
          show:false
        })
    },
    //查看详情
    toDetail(e){
        // console.log(e.currentTarget.dataset)
         let id = e.currentTarget.dataset.cid
         let index = null;
         this.data.dataList.forEach((v,i)=>{
           if(v.id==id)index=i
         })
         wx.navigateTo({
           url: '/packageA/pages/landDetail/index?cIndex='+index+'&cId='+id+'&item='+encodeURIComponent(JSON.stringify(this.data.dataList)), 
         })
    },
    toceshi(){
      
    },
  }
})
